package com.tapstitch.scm.common.enums;

import org.springframework.util.StringUtils;

public enum WarehouseEnums {

    GUANG_ZHOU(1L, "GZ1","广州沙湾仓", "广东省广州市番禺区沙湾镇福北路732号百世云仓"),
    GUANG_ZHOU2(2L, "GZ02","广州卓益仓", "广东省广州卓益仓"),
    GUANG_ZHOU3(3L, "GZ03","广州沃方仓", "广东省广州沃方仓"),

    GEAR_LAUNCH(4L, "GL01","Gear Launch", "美国盐城湖"),

    FULFILL_ENGINE(5L, "FE01","Fulfill Engine", "美国北卡"),

    LA(6L, "LA01","LA仓", "美国LA仓"),
    GUANG_ZHOU7(7L, "GZ07","广州沙湾次品仓", "广东省广州市番禺区沙湾镇福北路732号百世云仓"),

    GUANG_ZHOU8(8L, "GZ08","广州沙湾样衣仓", "广东省广州市番禺区沙湾镇福北路732号百世云仓"),

    CHANG_ZHOU1(9L, "CZ01","常州仓", ""),

    GZ2_NC(10L, "GZ2","广州南村仓", "中国广东省广州市番禺区新村大街14号"),
    ;

    private Long id;
    private String code;
    private String name;
    private String fullAddress;

    WarehouseEnums(Long id, String code, String name, String fullAddress) {
        this.id = id;
        this.code = code;
        this.name = name;
        this.fullAddress = fullAddress;
    }

    public static String getNameByCodeSplit(String warehouseCode) {
        String[] split = warehouseCode.split(",");
        StringBuilder stringBuilder = new StringBuilder();

        for (String str:split){
            stringBuilder.append(getByCode(str).getName()).append(",");
        }
        if(!StringUtils.isEmpty(stringBuilder)){
            return stringBuilder.substring(0,stringBuilder.length()-1);
        }
        return null;
    }

    public Long getId() {
        return id;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getFullAddress() {
        return fullAddress;
    }


    public static WarehouseEnums getById(Long value) {
        if(value == null) {
            return null;
        }
        for (WarehouseEnums warehouseEnum : values()) {
            if (warehouseEnum.getId().equals(value)) {
                return warehouseEnum;
            }
        }
        return null;
    }


    public static WarehouseEnums getByCode(String code) {
        if(!StringUtils.hasText(code)) {
            return null;
        }
        for (WarehouseEnums warehouseEnum : values()) {
            if (warehouseEnum.getCode().equals(code)) {
                return warehouseEnum;
            }
        }
        return null;
    }

    public static String getNameByCode(String code) {
        if(!StringUtils.hasText(code)) {
            return null;
        }
        for (WarehouseEnums warehouseEnum : values()) {
            if (warehouseEnum.getCode().equals(code)) {
                return warehouseEnum.getName();
            }
        }
        return null;
    }
}
